import cv2
import numpy as np

#返回灰度图像
def grayscale(image):
    return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 转置矩阵
def transformMatrix(m):
    rt = [[] for i in m[0]]    # m[0] 有几个元素，说明原矩阵有多少列。此处创建转置矩阵的行
    for ele in m:
        for i in range(len(ele)):
            # rt[i] 代表新矩阵的第 i 行
            # ele[i] 代表原矩阵当前行的第 i 列
            rt[i].append(ele[i])
    return rt
'''

用相差有变化识别出数字所在位置，如此便可以确定数字的位置
用右边和左边相减


'''

#880*550
def search_origin_point(image):
    image=grayscale(image)
    print(image.shape[0])
    histogram = np.sum(image, axis=0)


    print(len(histogram))
    print(histogram[:20])
    print(histogram[50:120])
    print(len(image[0]))


    for i in range(10,len(histogram)-50):
        if (histogram[i]==histogram[i+1]&histogram[i]==histogram[i+2]&histogram[i]!=histogram[3]):
            index=i;
            image_show=image.copy()
            for j in range(image.shape[0]-1):
                image_show[j][index]=0

            #转置image数组
            print(len(image[0]))
            #转置函数
            image_T=image.transpose()
            print("image[0]",len(image_T[0]))


            #统计数组中颜色分类个数
            myset=set(image_T[index]);
            for item in myset:
                print(item,np.sum(image_T[index]==item))
            print(index)

            break
    cv2.imshow("adsf",image_show)
    cv2.imshow("adsffdf", image)
    cv2.waitKey(0)

    #寻找颜色横线
    #print(image)